package com.we.weblog.domain;


import java.io.Serializable;

/**
 * 用于封装后端返回前端数据对象。对应json格式：
 * {"status":true, "data":{结果数据}, "message":"消息描述"}
 */
public class ResultVo implements Serializable {
    private static final String SUCCESS = "1";
    private static final String FAIL = "2";
    private String status;//后端返回结果正常为true，发生异常返回false
    private Object data;//后端返回结果数据对象
    private String message;//描述消息。如果不正常，就是错误信息

    //无参构造方法
    public ResultVo() {
    }

    /**
     * @param status 是否正常处理完成
     */
    public ResultVo(String status) {
        this.status = status;
    }

    /**
     * @param status 是否正常处理
     * @param data   处理结果数据
     */
    public ResultVo(String status, Object data) {
        this.status = status;
        this.data = data;
    }

    /**
     * @param status  是否正常处理
     * @param message 消息描述
     */
    public ResultVo(String status, String message) {
        this.status = status;
        this.message = message;
    }

    /**
     * @param status  是否正常处理
     * @param data    返回数据
     * @param message 消息描述
     */
    public ResultVo(String status, Object data, String message) {
        this.status = status;
        this.data = data;
        this.message = message;
    }

    public static ResultVo success(String message) {
        return new ResultVo(ResultVo.SUCCESS, null, message);
    }

    public static ResultVo success(Object data, String message) {
        return new ResultVo(ResultVo.SUCCESS, data, message);
    }

    public static ResultVo success(String status, Object data, String message) {
        return new ResultVo(status, data, message);
    }

    public static ResultVo fail(String message) {
        return new ResultVo(ResultVo.FAIL, null, message);
    }

    public static ResultVo fail(Object data, String message) {
        return new ResultVo(ResultVo.FAIL, data, message);
    }


    public static ResultVo fail(String status, Object data, String message) {
        return new ResultVo(status, data, message);
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
